package com.ruoyi.insurance.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.insurance.domain.ThreatIncident;
import com.ruoyi.insurance.service.IThreatIncidentService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 威胁事件Controller
 * 
 * @author ruoyi
 * @date 2024-09-10
 */
@RestController
@RequestMapping("/insurance/threat_incident")
public class ThreatIncidentController extends BaseController
{
    @Autowired
    private IThreatIncidentService threatIncidentService;

    /**
     * 查询威胁事件列表
     */
    @PreAuthorize("@ss.hasPermi('insurance:threat_incident:list')")
    @GetMapping("/list")
    public TableDataInfo list(ThreatIncident threatIncident)
    {
        startPage();
        List<ThreatIncident> list = threatIncidentService.selectThreatIncidentList(threatIncident);
        return getDataTable(list);
    }

    /**
     * 导出威胁事件列表
     */
    @PreAuthorize("@ss.hasPermi('insurance:threat_incident:export')")
    @Log(title = "威胁事件", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ThreatIncident threatIncident)
    {
        List<ThreatIncident> list = threatIncidentService.selectThreatIncidentList(threatIncident);
        ExcelUtil<ThreatIncident> util = new ExcelUtil<ThreatIncident>(ThreatIncident.class);
        util.exportExcel(response, list, "威胁事件数据");
    }

    /**
     * 获取威胁事件详细信息
     */
    @PreAuthorize("@ss.hasPermi('insurance:threat_incident:query')")
    @GetMapping(value = "/{threatId}")
    public AjaxResult getInfo(@PathVariable("threatId") Long threatId)
    {
        return success(threatIncidentService.selectThreatIncidentByThreatId(threatId));
    }

    /**
     * 新增威胁事件
     */
    @PreAuthorize("@ss.hasPermi('insurance:threat_incident:add')")
    @Log(title = "威胁事件", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ThreatIncident threatIncident)
    {
        return toAjax(threatIncidentService.insertThreatIncident(threatIncident));
    }

    /**
     * 修改威胁事件
     */
    @PreAuthorize("@ss.hasPermi('insurance:threat_incident:edit')")
    @Log(title = "威胁事件", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ThreatIncident threatIncident)
    {
        return toAjax(threatIncidentService.updateThreatIncident(threatIncident));
    }

    /**
     * 删除威胁事件
     */
    @PreAuthorize("@ss.hasPermi('insurance:threat_incident:remove')")
    @Log(title = "威胁事件", businessType = BusinessType.DELETE)
	@DeleteMapping("/{threatIds}")
    public AjaxResult remove(@PathVariable Long[] threatIds)
    {
        return toAjax(threatIncidentService.deleteThreatIncidentByThreatIds(threatIds));
    }
}
